import * as Cesium from 'cesium'
import gsap from 'gsap'
export default class SpritelinePropery{
    constructor(name = new Cesium.Color(0.7, 0.6, 1.0, 1.0)){
        this.name = name
        
        this.definitionChanged = new Cesium.Event()

        Cesium.Material._materialCache.addMaterial('Spriteline', {
            fabric: {
                type: 'Spriteline',
                uniforms: {
                    uTime: 0,
                    image: './texture/spriteline1.png'
                },
                source: `
                    czm_material czm_getMaterial(czm_materialInput materialInput)
                    {
                        czm_material material = czm_getDefaultMaterial(materialInput);
                        vec2 st = materialInput.st;
                        vec4 color = texture(image, vec2(fract(st.s + uTime),st.t));
                        material.alpha = color.a;
                        material.diffuse = color.rgb;
                        return material;
                    }
                `
            }
        })
        this.params = {
            uTime: 0
        }
        gsap.to(this.params, {
            uTime: 1,
            duration: 1,
            repeat: -1,
            ease: 'linear'
        })

    }
    getType() {
        return 'Spriteline'
    }
    getValue(time, reuslt) {
        reuslt.uTime = this.params.uTime
        return reuslt
    }
    equals(other) {
        return (other instanceof SpritelinePropery && this.name === other.name)
    }
}